package com.ms;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@EnableScheduling
public class ManagerSystemApplication {
    public static void main(String[] args) {
        SpringApplication.run(ManagerSystemApplication.class, args);
    }
    @Configuration
    public class CorsConfig implements WebMvcConfigurer {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**") // 对所有接口生效
                    .allowedOrigins("http://localhost:5173") // 允许的前端域名
                    .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的方法
                    .allowedHeaders("*") // 允许所有请求头
                    .allowCredentials(true) // 允许携带Cookie
                    .maxAge(3600); // 预检请求缓存1小时
        }
    }
}
